package com.example;

import com.google.common.base.Charsets;
import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnel;
import com.google.common.hash.PrimitiveSink;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.UUID;

@SpringBootApplication
public class DemoApplication {

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);

		BloomFilter<String> bloomFilter = BloomFilter.create(new Funnel<String>() {
			@Override
			public void funnel(String s, PrimitiveSink primitiveSink) {
				primitiveSink.putString(s, Charsets.UTF_8);
			}
		}, 1024*1024*32);

		for (int i = 0; i < 1000; i++) {
			String deal_id = UUID.randomUUID().toString();
			boolean exists = bloomFilter.mightContain(deal_id);
			if(!exists){
				bloomFilter.put(deal_id);
				System.out.println(i + ", 布隆过滤器中没有");
				continue;
			}

			System.out.println(i + ", ==布隆过滤器中存在");
		}


	}

}
